package cn.snailteam.recruitment.dao.impl;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import cn.snailteam.recruitment.entity.JobInfo;

/**
 * A data access object (DAO) providing persistence and search support for
 * JobInfo entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see cn.snailteam.recruitment.dao.impl.JobInfo
 * @author MyEclipse Persistence Tools
 */

public class JobInfoDAOImpl 
	extends HibernateDaoSupport implements  IJobInfoDAO{
	private static final Log log = LogFactory.getLog(JobInfoDAOImpl.class);
	// property constants
	public static final String AREA = "area";
	public static final String ADDRESS = "address";
	public static final String EMAIL = "email";
	public static final String HOME_URL = "homeUrl";
	public static final String CONCAT_PERSON = "concatPerson";
	public static final String SALARY = "salary";
	public static final String ADDITIONAL_CONDITION = "additionalCondition";
	public static final String WORK_LIFE = "workLife";
	public static final String RECRUIT_CATEGORY = "recruitCategory";
	public static final String JOB_DESC = "jobDesc";
	public static final String JOB_SPECIFICATION = "jobSpecification";
	public static final String PUBLISH_TIME = "publishTime";
	public static final String JOB_STATE = "jobState";

	protected void initDao() {
		// do nothing
	}

	public void save(JobInfo transientInstance) {
		log.debug("saving JobInfo instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(JobInfo persistentInstance) {
		log.debug("deleting JobInfo instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public JobInfo findById(java.lang.Integer id) {
		log.debug("getting JobInfo instance with id: " + id);
		try {
			JobInfo instance = (JobInfo) getHibernateTemplate().get(
					"cn.snailteam.recruitment.dao.impl.JobInfo", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(JobInfo instance) {
		log.debug("finding JobInfo instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding JobInfo instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from JobInfo as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByArea(Object area) {
		return findByProperty(AREA, area);
	}

	public List findByAddress(Object address) {
		return findByProperty(ADDRESS, address);
	}

	public List findByEmail(Object email) {
		return findByProperty(EMAIL, email);
	}

	public List findByHomeUrl(Object homeUrl) {
		return findByProperty(HOME_URL, homeUrl);
	}

	public List findByConcatPerson(Object concatPerson) {
		return findByProperty(CONCAT_PERSON, concatPerson);
	}

	public List findBySalary(Object salary) {
		return findByProperty(SALARY, salary);
	}

	public List findByAdditionalCondition(Object additionalCondition) {
		return findByProperty(ADDITIONAL_CONDITION, additionalCondition);
	}

	public List findByWorkLife(Object workLife) {
		return findByProperty(WORK_LIFE, workLife);
	}

	public List findByRecruitCategory(Object recruitCategory) {
		return findByProperty(RECRUIT_CATEGORY, recruitCategory);
	}

	public List findByJobDesc(Object jobDesc) {
		return findByProperty(JOB_DESC, jobDesc);
	}

	public List findByJobSpecification(Object jobSpecification) {
		return findByProperty(JOB_SPECIFICATION, jobSpecification);
	}

	public List findByPublishTime(Object publishTime) {
		return findByProperty(PUBLISH_TIME, publishTime);
	}

	public List findByJobState(Object jobState) {
		return findByProperty(JOB_STATE, jobState);
	}

	public List findAll() {
		log.debug("finding all JobInfo instances");
		try {
			String queryString = "from JobInfo";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public JobInfo merge(JobInfo detachedInstance) {
		log.debug("merging JobInfo instance");
		try {
			JobInfo result = (JobInfo) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(JobInfo instance) {
		log.debug("attaching dirty JobInfo instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(JobInfo instance) {
		log.debug("attaching clean JobInfo instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static JobInfoDAOImpl getFromApplicationContext(ApplicationContext ctx) {
		return (JobInfoDAOImpl) ctx.getBean("JobInfoDAO");
	}
}